package edu.hebeu.evil.freshmenguide.Activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import edu.hebeu.evil.freshmenguide.R;

/********************************************
 * 工程名：FreshmenGuide
 * 包名：edu.hebeu.evil.freshmenguide.Activity
 * 时间：16-7-7 下午12:03
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：基础Activity
 ********************************************/
public abstract class BaseActivity extends AppCompatActivity
{
    public abstract int setContentView();

    public abstract String setToolbarTitle();

    public abstract void onCreate();

    private Toolbar toolbar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(setContentView());
        initView();
        setToolbar(setToolbarTitle());
        onCreate();
    }


    /**
     * 初始化控件
     */
    private void initView()
    {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
    }

    /**
     * 设置toolbar
     */
    private void setToolbar(String title)
    {
        toolbar.setTitle(title);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null)
        {
            getSupportActionBar().setHomeButtonEnabled(true);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    /**
     * toolbar返回键监听
     *
     * @param item
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        if (item.getItemId() == android.R.id.home)
        {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
